package com.tanhua.server.service;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.common.mapper.QuestionMapper;
import com.tanhua.common.pojo.Question;
import com.tanhua.common.pojo.UserInfo;
import com.tanhua.common.utils.UserThreadLocal;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class QuestionService {

    @Autowired
    private QuestionMapper questionMapper;


    //保存陌生人问题
    public Boolean saveUserQuestions(Long userId,String content) {
        Question question = new Question();
        question.setTxt(content);
        question.setUserId(userId);

        return questionMapper.insert(question) >0 ;

    }

    //修改陌生人问题
    public Boolean updateUserQuestions(Long userId,String content) {
        Question question = new Question();
        question.setTxt(content);
        question.setUserId(userId);
        QueryWrapper<Question> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        int i = questionMapper.update(question,queryWrapper);
        return i>0;

    }

    public Question queryQuestion(Long userId) {
        QueryWrapper<Question> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        return questionMapper.selectOne(queryWrapper);
    }
}
